package com.ruoyi.material.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.MaterialUseRequest;
import com.ruoyi.material.service.IMaterialUseRequestService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊材领用管理Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@Controller
@RequestMapping("/material/request")
public class MaterialUseRequestController extends BaseController
{
    private String prefix = "material/request";

    @Autowired
    private IMaterialUseRequestService materialUseRequestService;

    @RequiresPermissions("material:request:view")
    @GetMapping()
    public String request()
    {
        return prefix + "/request";
    }

    /**
     * 查询焊材领用管理列表
     */
    @RequiresPermissions("material:request:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaterialUseRequest materialUseRequest)
    {
        startPage();
        List<MaterialUseRequest> list = materialUseRequestService.selectMaterialUseRequestList(materialUseRequest);
        return getDataTable(list);
    }

    /**
     * 导出焊材领用管理列表
     */
    @RequiresPermissions("material:request:export")
    @Log(title = "焊材领用管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaterialUseRequest materialUseRequest)
    {
        List<MaterialUseRequest> list = materialUseRequestService.selectMaterialUseRequestList(materialUseRequest);
        ExcelUtil<MaterialUseRequest> util = new ExcelUtil<MaterialUseRequest>(MaterialUseRequest.class);
        return util.exportExcel(list, "焊材领用管理数据");
    }

    /**
     * 新增焊材领用管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊材领用管理
     */
    @RequiresPermissions("material:request:add")
    @Log(title = "焊材领用管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaterialUseRequest materialUseRequest)
    {
        return toAjax(materialUseRequestService.insertMaterialUseRequest(materialUseRequest));
    }

    /**
     * 修改焊材领用管理
     */
    @RequiresPermissions("material:request:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MaterialUseRequest materialUseRequest = materialUseRequestService.selectMaterialUseRequestById(id);
        mmap.put("materialUseRequest", materialUseRequest);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊材领用管理
     */
    @RequiresPermissions("material:request:edit")
    @Log(title = "焊材领用管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaterialUseRequest materialUseRequest)
    {
        return toAjax(materialUseRequestService.updateMaterialUseRequest(materialUseRequest));
    }

    /**
     * 删除焊材领用管理
     */
    @RequiresPermissions("material:request:remove")
    @Log(title = "焊材领用管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(materialUseRequestService.deleteMaterialUseRequestByIds(ids));
    }
}
